package longestConsecutive128;

import java.util.Arrays;

public class LongestConsecutive {
    public int longestConsecutive(int[] nums) {
        Arrays.sort(nums);
        int len = nums.length;
        if(len == 0) return 0;

        int count = 0;
        int res = 0;
        for (int i = 1; i < nums.length; i++) {
            if(nums[i] - nums[i-1] == 1){
                count++;
                res = Math.max(res, count);
            }else if(nums[i] - nums[i-1] == 0){
                continue;
            }else {
                count = 1;
            }
        }
        return res;
    }
}
